package com.uton.rfidcontroller.view.fragment;

import com.uton.rfidcontroller.R;
import com.uton.rfidcontroller.databinding.FragmentAlreadyDoTaskBinding;
import com.uton.rfidcontroller.model.CarDealerListModel;
import com.uton.rfidcontroller.model.CarListModel;
import com.uton.rfidcontroller.view.base.BaseRecyclerViewAlreadyDoFragment;
import com.uton.rfidcontroller.viewmodel.fragment_model.AlreadyDoTaskViewModel;

import java.util.List;

import io.reactivex.ObservableTransformer;

/**
 * Created by 王家宝 on 2017/9/5.
 * Email:639586819@qq.com
 * Tel:18241150668
 */

public class AlreadyDoTaskFragment extends
        BaseRecyclerViewAlreadyDoFragment<FragmentAlreadyDoTaskBinding, AlreadyDoTaskViewModel, CarListModel> {

    @Override
    protected void doOnRefresh() {
        getViewModel().refreshData();
    }

    @Override
    protected void doOnLoadMore() {
        getViewModel().doOnLoadMore();
    }

    @Override
    public int setLayout() {
        return R.layout.fragment_already_do_task;
    }

    @Override
    public void inject() {
        getBinding().setAlreadyDoTaskViewModel(getViewModel());
    }

    @Override
    protected AlreadyDoTaskViewModel setViewModel() {
        return new AlreadyDoTaskViewModel() {
            @Override
            public void doOnRefreshSuccess(List<CarDealerListModel> tResponse) {
                refreshComplete(tResponse);
                if (isRefreshFirst()) {
                    showData.set(true);
                    showLoading.set(false);
                }
            }

            @Override
            public void doOnRefreshError() {
                stopRefresh();
                if (isRefreshFirst()) {
                    showData.set(true);
                    showLoading.set(false);
                }
            }

            @Override
            public void doOnLoadMoreSuccess(List<CarDealerListModel> tResponse) {

            }

            @Override
            public void doOnLoadMoreError() {

            }

            @Override
            public ObservableTransformer setObservable() {
                return compose(bindToLifecycle());
            }
        };
    }
}
